import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.RandomUtil;
import com.bigmodel.contant.AmdbId;
import com.bigmodel.contant.StepId;
import com.bigmodel.contant.SystemName;
import com.bigmodel.contant.VerbName;
import com.bigmodel.entity.QAEntity;
import com.bigmodel.util.ExcelUtil;
import com.bigmodel.util.FtlUtil;
import org.junit.Test;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SqlTrain_1027_v1 {

    private final static String OUT_PATH = "D:\\javacode\\bigmodel\\bigmodel\\sql_train_1027_v1\\";

    private final static String FREEMARKER_BASE_PATH = "sft/sql_train_1027_v1/";

    private static final int randomNumber = 20;


    private static List<String> verbList = null;
    private static List<String> systemNameList = null;
    private static List<String> nameList = null;
    private static List<String> stepIdList = null;

    private static final int HOUR12MAX = 12;
    private static final int HOUR23MAX = 23;
    private static final int MINUTE59MAX = 59;
    private static String[] chinese_0_59 = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "二十一", "二十二", "二十三", "二十四", "二十五", "二十六", "二十七", "二十八", "二十九", "三十", "三十一", "三十二", "三十三", "三十四", "三十五", "三十六", "三十七", "三十八", "三十九", "四十", "四十一", "四十二", "四十三", "四十四", "四十五", "四十六", "四十七", "四十八", "四十九", "五十", "五十一", "五十二", "五十三", "五十四", "五十五", "五十六", "五十七", "五十八", "五十九"};
    private static String[] number_0_59 = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"};

    private static String[] chinese_0_12 = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};
    private static String[] number_0_12 = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};

    private static String[] chinese_0_23 = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "二十一", "二十二", "二十三"};
    private static String[] number_0_23 = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"};

    private static String[] chinese_1_30 = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "二十一", "二十二", "二十三", "二十四", "二十五", "二十六", "二十七", "二十八", "二十九", "三十"};
    private static String[] number_1_30 = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"};


    static {
        systemNameList = ListUtil.toList(SystemName.LIST_ARRAY);
        verbList = ListUtil.toList(VerbName.LIST_ARRAY);
        nameList = ListUtil.toList(AmdbId.LIST_ARRAY);
        stepIdList = ListUtil.toList(StepId.LIST_ARRAY);
    }


    public static void main(String[] args) {
        List<QAEntity> allEntityList = new ArrayList<>();
        allEntityList.addAll(T001());
        allEntityList.addAll(T002());
        allEntityList.addAll(T003());
        ExcelUtil.createExcelSql(allEntityList, OUT_PATH + "T001.xls");
    }


    private static List<QAEntity>  T001() {
        String code = "T001";
        String category = "";

        List<QAEntity> qaEntityList = null;
        List<QAEntity> allEntityList = new ArrayList<>();

        String[] questionArr = {
                "昨天哪类工单最多？",
                "昨天哪类工单最多",
                "昨天哪类工单最多啊",
                "帮我查一下昨天哪类工单最多？",
                "帮我查一下昨天哪类工单最多",
                "帮我查一下昨天哪类工单最多啊",
                "查一下昨天哪类工单最多？",
                "查一下昨天哪类工单最多",
                "查一下昨天哪类工单最多啊",
                "帮我统计一下昨天哪类工单最多？",
                "帮我统计一下昨天哪类工单最多",
                "帮我统计一下昨天哪类工单最多啊",
                "统计一下昨天哪类工单最多？",
                "统计一下昨天哪类工单最多",
                "统计一下昨天哪类工单最多啊",
                "帮我统计下昨天哪类工单最多？",
                "帮我统计下昨天哪类工单最多",
                "帮我统计下昨天哪类工单最多啊",
                "统计下昨天哪类工单最多？",
                "统计下昨天哪类工单最多",
                "统计下昨天哪类工单最多啊",
                "统计昨天哪类工单最多？",
                "统计昨天哪类工单最多",
                "统计昨天哪类工单最多啊",
                "搜索下昨天哪类工单最多？",
                "搜索下昨天哪类工单最多",
                "搜索下昨天哪类工单最多啊"
        };

        {
            qaEntityList = new ArrayList<>();
            for (String question : questionArr) {
                Map<String, Object> map = new HashMap<>();
                map.put("question", question);
                String prompt = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/prompt.ftl");
                String answerContent = null;
                String sq1 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq1.ftl");
                String sq2 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq2.ftl");
                String sq3 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq3.ftl");
                QAEntity qa = new QAEntity(code, category, prompt, answerContent);
                qa.setPrompt(prompt);
                qa.setQuestionContent(question);
                qa.setSql1(sq1);
                qa.setSql2(sq2);
                qa.setSql3(sq3);
                qaEntityList.add(qa);
            }
            for (String question : questionArr) {
                Map<String, Object> map = new HashMap<>();
                map.put("question", question.replace("哪类", "哪些"));
                String prompt = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/prompt.ftl");
                String answerContent = null;
                String sq1 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq1.ftl");
                String sq2 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq2.ftl");
                String sq3 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq3.ftl");
                QAEntity qa = new QAEntity(code, category, prompt, answerContent);
                qa.setPrompt(prompt);
                qa.setQuestionContent(question);
                qa.setSql1(sq1);
                qa.setSql2(sq2);
                qa.setSql3(sq3);
                qaEntityList.add(qa);
            }
            for (String question : questionArr) {
                Map<String, Object> map = new HashMap<>();
                map.put("question", question.replace("哪些", "哪种"));
                String prompt = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/prompt.ftl");
                String answerContent = null;
                String sq1 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq1.ftl");
                String sq2 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq2.ftl");
                String sq3 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq3.ftl");
                QAEntity qa = new QAEntity(code, category, prompt, answerContent);
                qa.setPrompt(prompt);
                qa.setQuestionContent(question);
                qa.setSql1(sq1);
                qa.setSql2(sq2);
                qa.setSql3(sq3);
                qaEntityList.add(qa);
            }
            for (String question : questionArr) {
                Map<String, Object> map = new HashMap<>();
                map.put("question", question.replace("哪些", "哪种类型"));
                String prompt = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/prompt.ftl");
                String answerContent = null;
                String sq1 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq1.ftl");
                String sq2 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq2.ftl");
                String sq3 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq3.ftl");
                QAEntity qa = new QAEntity(code, category, prompt, answerContent);
                qa.setPrompt(prompt);
                qa.setQuestionContent(question);
                qa.setSql1(sq1);
                qa.setSql2(sq2);
                qa.setSql3(sq3);
                qaEntityList.add(qa);
            }
            qaEntityList = random50List(qaEntityList);
            allEntityList.addAll(qaEntityList);
        }

        return allEntityList;
    }


    private static List<QAEntity>  T002() {
        String code = "T002";
        String category = "";

        List<QAEntity> qaEntityList = null;
        List<QAEntity> allEntityList = new ArrayList<>();

        String[] questionArr = {
                "有余额被停机的主要问题是什么？",
                "有余额被停机的主要问题是什么",
                "有余额被停机的主要问题是哪些",
                "有余额被停机的主要问题是哪种",
                "有余额被停机的主要问题是哪种类型",
                "有余额被停机的主要问题是哪种类型？",
                "有余额被停机的主要问题是哪些类型",
                "有余额被停机的主要问题是哪类",
                "余额被停机的主要问题是什么？",
                "余额被停机的主要是什么问题？",
                "余额被停机的主要是什么问题",
                "帮我查一下余额被停机的主要是什么问题",
                "帮我查一下余额被停机的主要是什么问题？",
                "继续查下余额被停机的主要是什么问题",
                "继续查下余额被停机的主要是什么问题？",
                "继续查下余额被停机的主要是什么问题",
                "继续查下余额被停机的主要是什么问题？"
        };

        {
            qaEntityList = new ArrayList<>();
            for (String question : questionArr) {
                Map<String, Object> map = new HashMap<>();
                map.put("question", question);
                map.put("complaintType", "余额被停机");
                String prompt = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/prompt.ftl");
                String answerContent = null;
                String sq1 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq1.ftl");
                String sq2 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq2.ftl");
                String sq3 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq3.ftl");
                QAEntity qa = new QAEntity(code, category, prompt, answerContent);
                qa.setPrompt(prompt);
                qa.setQuestionContent(question);
                qa.setSql1(sq1);
                qa.setSql2(sq2);
                qa.setSql3(sq3);
                qaEntityList.add(qa);
            }
            qaEntityList = random50List(qaEntityList);
            allEntityList.addAll(qaEntityList);
        }


        return allEntityList;
    }


    private static List<QAEntity>  T003() {
        String code = "T003";
        String category = "";

        List<QAEntity> qaEntityList = null;
        List<QAEntity> allEntityList = new ArrayList<>();

        String[] questionArr = {
                "查询各地客服投诉工单分布情况",
                "查询一下各地客服投诉工单分布情况",
                "统计各地客服投诉工单分布情况",
                "统计一下各地客服投诉工单分布情况",
                "查询各地客服投诉工单分布情况？",
                "查询一下各地客服投诉工单分布情况？",
                "统计各地客服投诉工单分布情况？",
                "统计一下各地客服投诉工单分布情况？",
                "统计客服投诉工单分布情况？"
        };

        {
            qaEntityList = new ArrayList<>();
            for (String question : questionArr) {
                Map<String, Object> map = new HashMap<>();
                map.put("question", question);
                String prompt = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/prompt.ftl");
                String answerContent = null;
                String sq1 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq1.ftl");
                String sq2 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq2.ftl");
                String sq3 = FtlUtil.generateContent(map, FREEMARKER_BASE_PATH + code + "/sq3.ftl");
                QAEntity qa = new QAEntity(code, category, prompt, answerContent);
                qa.setPrompt(prompt);
                qa.setQuestionContent(question);
                qa.setSql1(sq1);
                qa.setSql2(sq2);
                qa.setSql3(sq3);
                qaEntityList.add(qa);
            }
            qaEntityList = random50List(qaEntityList);
            allEntityList.addAll(qaEntityList);
        }


        return allEntityList;
    }



    public static List<QAEntity> random50List(List<QAEntity> allList) {
        if (allList.size() > 10000) {
            List<QAEntity> newList = new ArrayList<>();
            for (int i = 0; i < 10000; i++) {
                newList.add(allList.get(RandomUtil.randomInt(0, allList.size())));
            }
            return newList;
        } else {
            return allList;
        }
    }


}
